<template>
  <div class="container_detail introduce-edit">
    <div class="header">
      <p>平台介绍</p>
      <el-button class="link" type="primary">
        <router-link :to="{path:'teamList',query: { currentPage: currentPage }}" style="color: #fff;">返回</router-link>
      </el-button>
    </div>
    <div class="main">
      <el-form
        :model="user"
        :rules="rules"
        ref="user"
        label-width="150px"
        class=""
      >
        <el-form-item
          label="Logo："
          prop="imageKey"
        >
          <el-upload
            class="avatar-uploader"
            :action="upLoadUrl"
            :show-file-list="false"
            :before-upload="beforeAvatarUpload1"
           >
            <img
              v-if="imageUrl"
              :src="imageUrl"
              class="avatar"
            >
            <i
              v-else
              class="el-icon-plus avatar-uploader-icon"
            ></i>
          </el-upload>
        </el-form-item>
        <el-form-item
        label="联系电话："
        prop="notice"
        >
            <el-input
              v-model="user.mobile  "
              placeholder="请输入"
            ></el-input>
        </el-form-item>
        <el-form-item
          label="关于此平台："
          prop="userName"
        >
            <bg-editor
                :minHeight="300"
                :uploadUrl="upLoadUrl"
                :content="user.detail"
                @editorData='editorInfo'
            >
            </bg-editor>
        </el-form-item>
        <el-form-item
          label="帮助指南："
          prop="helpGuide"
        >
            <bg-editor
                id="helpGuide"
                :minHeight="300"
                :uploadUrl="upLoadUrl"
                :content="user.helpGuide"
                @editorData='editorInfo1'
            >
            </bg-editor>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="handleSave('user')"
            style="margin-left:150px"
          >保存</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
let CONSTANT = require("../../constant/constant.js");
let common = require("../../common.js");

export default {
  data() {
    return {
      id: "",
      info: "",
      // 返回 导航页码
      currentPage: 1,
      dialogVisible: false,
      pictureUrl: "",
      user: {
        "mobile":"",
        "detail": "",
        "id": "",
        "photoIds": "",
        helpGuide:''
      },
      rules: {
        photoIds: [{ required: true, message: "请上传Logo", trigger: "blur" }],
        detail: [
          { required: true, message: "请输入内容", trigger: "blur" }
        ],
        helpGuide: [
          { required: true, message: "请输入帮助指南", trigger: "blur" }
        ],
      },
      imageUrl:'',
      upLoadUrl:'',
      content:""
    };
  },
  mounted() {
      let sessionId = sessionStorage.getItem("sessionId");
      this.upLoadUrl =
      CONSTANT.URL.SYSTEM.UPLOADFILEBYCOS + "?sessionId=" + sessionId;
     this.getDetail();
  },
  components: {
    "bg-editor": () => import("../common/bg-editor.vue")
  },
  methods: {
      editorInfo(e) {
        this.user.detail = e
      },
      editorInfo1(e) {
        this.user.helpGuide = e
      },
      beforeAvatarUpload1(file) {
        let url = CONSTANT.URL.SYSTEM.UPLOADFILEBYCOS;
        let param = {
          suffix: file.name.split(".")[1], // 文件后缀  png
          contentType: file.type // 文件类型  image/png
        };
        console.log(param,'')
        common.requestAjax(url, null, param, res => {
            console.log(res,'eeeeeee')
          this.upLoadUrl = res.data.bussData.uploadUrl;
          common.uploadFile(this.upLoadUrl, file, file.type, res1 => {
           this.imageUrl = res.data.bussData.downloadUrl
           this.user.photoIds = res.data.bussData.fileKey
          })
        });
      },
     getDetail() {
      let url = CONSTANT.URL.LIST.findEsPlatformById;
      let data = { id:1}
      common.requestAjax(url, JSON.stringify(data), null, res => {
        this.user = res.data.bussData;
        this.imageUrl = res.data.bussData.images[0].fileUrl
        this.user.photoIds = res.data.bussData.images[0].fileKey
        this.user.detail = res.data.bussData.detail
        this.user.mobile = res.data.bussData.mobile
        this.user.helpGuide = res.data.bussData.helpGuide
        $('#summernote').summernote('code',res.data.bussData.detail)
        $('#helpGuide').summernote('code',res.data.bussData.helpGuide)
      });
    },
    checkImage(url) {
      this.pictureUrl = url;
      this.dialogVisible = true;
    },
    handleSave: function(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          let url = CONSTANT.URL.LIST.saveEsPlatform;
          common.requestAjax(url, JSON.stringify(this.user), null, res => {
            if (res.status == 200) {
              this.$message({
                type: "success",
                message: "操作成功!"
              });
            } else {
              this.$message({
                type: "warning",
                message: res.msg
              });
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>
<style lang="scss">
.introduce-edit {
  .el-form-item {

    
  }
    .el-input {
      width:220px;
    }
    .el-select {
      width: 220px;
      .el-input {
        width: 100%;
      }
    }


  .item-value {
    .el-input {
      width:220px;
    }
    .el-select {
      width: 220px;
      .el-input {
        width: 100%;
      }
    }
  }
}
</style>

